package com.t216.dm216.controller;

import cn.hutool.core.bean.BeanUtil;
import com.t216.dm216.common.Result;
import com.t216.dm216.pojo.DmItemComment;
import com.t216.dm216.pojo.dto.DmItemCommentDTO;
import com.t216.dm216.service.DmItemCommentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/item/api/v")
public class DmItemApiViewController {
    @Resource
    private DmItemCommentService itemCommentService;
    @PostMapping("/commitItemComment")
    public Result commitItemComment(@RequestBody DmItemCommentDTO itemCommentDTO){
        DmItemComment itemComment = new DmItemComment();
        /*复制的是同名属性*/
        BeanUtil.copyProperties(itemCommentDTO,itemComment);
        itemComment.setCreatedTime(new Date());//这个数据是没有
        itemComment.setContent(itemCommentDTO.getComment());//这个不是同名属性
        return itemCommentService.addItemComment(itemComment)?Result.success() : Result.error("1000");
    }
}
